package edu.udo.sopra10.chaturaji.util;

/**
 * A class containing utilities to simplify use of the {@link Clonable} API.
 * 
 * @author Simon Dierl
 */
public class CloneUtil {
	/**
	 * A type-safe accessor for {link Object#clone()}. This method clones an
	 * object and immediately attempts to cast the clone to the cloned object's
	 * class. By contract, the cast MUST succeed.
	 * 
	 * @param <T>
	 *            the type of class that is cloned.
	 * @param object
	 *            the object to clone.
	 * @return a clone of the object.
	 */
	@SuppressWarnings("unchecked")
	public static <T extends Clonable> T clone(final T object) {
		return (T) object.getClass().cast(object.clone());
	}
}
